"""Build DAOS client"""
import daos_build

def scons():
    """Execute build"""
    Import('env', 'base_env', 'API_VERSION', 'prereqs')

    env.AppendUnique(LIBPATH=[Dir('.')])
    base_env.AppendUnique(LIBPATH=[Dir('.')])
    denv = env.Clone()
    prereqs.require(denv, 'protobufc')
    libdaos_tgts = denv.SharedObject(Glob('*.c'))

    Import('dc_pool_tgts', 'dc_co_tgts', 'dc_obj_tgts', 'dc_placement_tgts')
    Import('dc_mgmt_tgts', 'dc_array_tgts', 'dc_kv_tgts', 'dc_security_tgts')
    libdaos_tgts += dc_pool_tgts + dc_co_tgts + dc_placement_tgts + dc_obj_tgts
    libdaos_tgts += dc_mgmt_tgts + dc_array_tgts + dc_kv_tgts + dc_security_tgts
    Export('libdaos_tgts')

    if prereqs.client_requested():
        libdaos= daos_build.library(env, 'daos', libdaos_tgts,
                                     SHLIBVERSION=API_VERSION,
                                     LIBS=['daos_common'])
        if hasattr(env, 'InstallVersionedLib'):
            env.InstallVersionedLib('$PREFIX/lib64/', libdaos,
                                    SHLIBVERSION=API_VERSION)
        else:
            env.Install('$PREFIX/lib64/', libdaos)

    if prereqs.test_requested():
        SConscript('tests/SConscript', exports='denv')

if __name__ == "SCons.Script":
    scons()
